package cn.saltybe.analysis.scheduler;

import cn.saltybe.analysis.analyze.*;
import cn.saltybe.analysis.crawler.InitGecco;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
public class CrawlerScheduler {
    @Scheduled(fixedRate = 1000 * 60 * 60)
    private void configureTask() {
        System.out.println("执行定时任务：爬取分析 58同城 房地产数据");
        try {
            new InitGecco(true);
            System.out.println("爬取 58同城 房地产数据完成。");

            System.out.println("执行定时任务：分析 新房数据");
            try {
                NewHouseAnalyze.importData();
                NewHouseAnalyze.analyzeData();
                NewHouseAnalyze.exportData();
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("分析 新房数据 失败。");
            }

            System.out.println("执行定时任务：分析 二手房数据");
            try {
                SecondHandHouseAnalyze.importData();
                SecondHandHouseAnalyze.analyzeData();
                SecondHandHouseAnalyze.exportData();
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("分析 二手房数据 失败。");
            }

            System.out.println("执行定时任务：分析 整租房数据");
            try {
                WholeRentingHouseAnalyze.importData();
                WholeRentingHouseAnalyze.analyzeData();
                WholeRentingHouseAnalyze.exportData();
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("分析 整租房数据 失败。");
            }

            System.out.println("执行定时任务：分析 合租房数据");
            try {
                ShareRentingHouseAnalyze.importData();
                ShareRentingHouseAnalyze.analyzeData();
                ShareRentingHouseAnalyze.exportData();
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("分析 合租房数据 失败。");
            }

            System.out.println("爬取分析 58同城 房地产数据完毕。");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("爬取 58同城 房地产数据失败。");
        }
    }
}
